package com.hdax.dm.mapstructs;


import com.hdax.common.dto.HotItemDto;
import com.hdax.dm.entity.base.DmImage;
import com.hdax.dm.entity.item.DmItem;
import com.hdax.dm.openfeign.BaseFeign;
import org.mapstruct.Mapper;
import org.mapstruct.Mapping;
import org.mapstruct.Mappings;
import org.springframework.beans.factory.annotation.Autowired;

import java.util.List;

@Mapper(componentModel = "spring")
public abstract class HotItemDtoMapper {

    @Autowired
    private BaseFeign baseFeign;

    @Mappings({
            @Mapping(target = "imgUrl",expression = "java(getImageUrl(soucres.getId()))")
    })
    public abstract HotItemDto toTarger(DmItem soucres);
    public abstract List<HotItemDto> toTargerList(List<DmItem> soucres);
    protected String getImageUrl(Long itemId){
        DmImage image = baseFeign.image(itemId);
        return image==null?"":image.getImgUrl();
    }
}
